import { httpClient } from '../base/request'
import { paymentAPIConfig } from '../const/api'

export const PaymentService = {
  async getAllProducts() {
    const { data } = await httpClient.request<Payment.AllProductResponse>({
      url: paymentAPIConfig.allProducts,
    })
    return data
  },
  async subscribeMember(params: Payment.MemberSubscribeRequest) {
    const { data } = await httpClient.request<Payment.MemberSubscribeResponse>({
      url: paymentAPIConfig.subscribeMember,
      data: params,
    })
    return data
  },
  async payCreditsWithNumber(params: Payment.CreditsPayRequest) {
    const { data } = await httpClient.request<Payment.CreditsPayResponse>({
      url: paymentAPIConfig.creditProduct,
      data: params,
    })
    return data
  },
  // PayPal订阅相关API
  async createPayPalSubscription(params: Payment.PayPalSubscriptionRequest) {
    const { data } = await httpClient.request<Payment.PayPalSubscriptionResponse>({
      url: paymentAPIConfig.createPayPalSubscription,
      data: params,
    })
    return data
  },
  async capturePayPalSubscription(params: Payment.PayPalSubscriptionCaptureRequest) {
    const { data } = await httpClient.request<Payment.PayPalSubscriptionCaptureResponse>({
      url: paymentAPIConfig.capturePayPalSubscription,
      data: params,
    })
    return data
  },
  async createPayPalOneTimePurchase(params: Payment.PayPalOneTimePurchaseRequest) {
    const { data } = await httpClient.request<Payment.PayPalOneTimePurchaseResponse>({
      url: paymentAPIConfig.createPayPalOneTimePurchase,
      data: params,
    })
    return data
  },
  async capturePayPalOneTimePurchase(params: Payment.PayPalOneTimePurchaseCaptureRequest) {
    const { data } = await httpClient.request<Payment.PayPalOneTimePurchaseCaptureResponse>({
      url: paymentAPIConfig.capturePayPalOneTimePurchase,
      data: params,
    })
    return data
  },
}
